﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PurchaseLookupCtrl.ascx.cs" Inherits="WebUI.Controls.POSControls.PurchaseLookupCtrl" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<script type="text/javascript">
    var IMEILength = <%= WebUI.BasePage.SysVars.IMEILength %>;
    
    function txtIMEI_onchange(txt) {
        if(!isNumeric(txt.value)){
            alert("Invalid IMEI number!");
            txt.value = "";
            return;
        }
        
        if(txt.value.length >= IMEILength){
            document.getElementById("<%=btnAddIMEI.ClientID %>").click();
            txt.value='';
        }
    }       
    
    function isNumeric(value) {
        if (value != null && !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
            return true;
    }
    
    function onQtyLostFocus(txt){        
        var qty = txt.value;
        if (qty == '') qty = 1;
        if(qty == '0')
        {
            alert("Quantity = 0 is not allowed!");
            qty = 1;
            
        }
        
        txt.value = qty;
    }
    
    function onAddProduct() {
        var returnValue = window.showModalDialog('<%=GetProductEditPageLink() %>' + 'mode=new', '', 'dialogWidth=800px;dialogHeight=600px;resizable=no;help=no;unadorned=yes;');

        if(returnValue != undefined)
            document.getElementById("<%=hidSessionID.ClientID %>").value = returnValue;
        return returnValue != undefined;
    }

    function focusIMEI(){
        document.getElementById('<%= txtIMEI.ClientID %>').focus();
    }
</script>


<asp:Panel ID="mainPanel" runat="server">
    <table width="100%">
        <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage" ID="label9" runat="server" Text="Bar Code:"></asp:Label>
            </td>
            <td style="text-align:left; vertical-align:top;">
                <asp:Panel ID="panelBarCode" runat="server" DefaultButton="btnBarCode" >
                    <asp:TextBox Width="200px" ID="txtBarCode" runat="server"  onfocus='this.select();' ></asp:TextBox><br/>
                    <asp:Label class="labelNote" Text="(*) Scan and press Enter." runat="server" ID="label10"></asp:Label>
                    <asp:Button ID="btnBarCode" runat="server" OnClick="btnBarCode_OnClick" style="display:none" />
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage" ID="label3" runat="server" Text="Category:"></asp:Label>
            </td>
            <td style="text-align:left; vertical-align:top; ">
                <asp:DropDownList Width="200px" ID="ddlCategory" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCategory_OnSelectedIndexChanged"></asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage" ID="label4" runat="server" Text="Brand:"></asp:Label>
            </td>
            <td style="text-align:left; vertical-align:top;">
                <asp:DropDownList Width="100px" ID="ddlBrand" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlBrand_OnSelectedIndexChanged"></asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage" ID="label2" runat="server" Text="Product:"></asp:Label>
            </td>
            <td style="text-align:left; vertical-align:top;">
                <asp:DropDownList Width="200px" ID="ddlProduct" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlProduct_OnSelectedIndexChanged"></asp:DropDownList>
            </td>
        </tr>
        <div id="divIMEI" runat="server">
        <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage"  ID="label1" runat="server" Text="IMEI:"></asp:Label>
            </td>
            <td>
                <asp:Panel ID="panelIMEI" runat="server" DefaultButton="btnAddIMEI" >
                    <asp:TextBox ID="txtIMEI" runat="server" Width="200px" onfocus='this.select();' ></asp:TextBox><br />
                    <asp:Label class="labelNote" Text="(*) Scan and press Enter." runat="server" ID="label8"></asp:Label>
                    <asp:Button ID="btnAddIMEI" runat="server" OnClick="btnAddIMEI_Click" style="display:none" />
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <table class="toolbar" Width="200px">
                    <tr>
                        <td>
                            <asp:LinkButton class="tbbutton" ID="btnDelete" runat="server" ToolTip="Delete selected IMEI" OnClick="btnDelete_Click">
                                <img src="../../Images/Delete.gif" style='vertical-align: middle' /><asp:Label ID="label7"
                                    class='labelMessage' runat="server" Text="Delete" ></asp:Label>
                            </asp:LinkButton>
                            <asp:LinkButton class="tbbutton" ID="btnClear" runat="server" ToolTip="Clear all" OnClick="btnClear_Click">
                                <img src="../../Images/edit-clear.png" style='vertical-align: middle' /><asp:Label
                                    ID="label6" class='labelMessage' runat="server" Text="Clear" ></asp:Label>
                            </asp:LinkButton>
                        </td>
                    </tr>
                </table>
                <asp:ListBox ID="lstIMEI" runat="server" Height="150px" Width="200px"></asp:ListBox>
            </td>
        </tr>
        </div>
        <div id="divQty" runat="server">
         <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage" ID="label5" runat="server" Text="Quantity:"></asp:Label>
            </td>
            <td style="text-align:left; vertical-align:top;">
                <asp:TextBox Width="100px" ID="txtQuantity" runat="server"  onfocus="this.select();" onblur='onQtyLostFocus(this);'></asp:TextBox>
                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" TargetControlID="txtQuantity"  FilterType="Numbers" runat="server">
                </cc1:FilteredTextBoxExtender>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage" ID="label11" runat="server" Text="Sale Price:"></asp:Label>
            </td>
            <td style="text-align:left; vertical-align:top;">
                <asp:Label CssClass="labelMessage"  ID="lblSalePrice" runat="server"></asp:Label>
                <asp:TextBox ValidationGroup="SavePrice"  Width="100px" ID="txtSalePrice" runat="server" onfocus="this.select();"></asp:TextBox>
                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender6" TargetControlID="txtSalePrice" FilterType="Numbers,Custom" ValidChars=".-" runat="server">
                </cc1:FilteredTextBoxExtender>
                <asp:RequiredFieldValidator ValidationGroup="SavePrice" ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtSalePrice" Display="Dynamic" CssClass="requiredField"
                                    ErrorMessage="required" Text="required"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage" ID="label13" runat="server" Text="Cost:"></asp:Label>
            </td>
            <td style="text-align:left; vertical-align:top;">
                <asp:Label CssClass="labelMessage"  ID="lblCost" runat="server"></asp:Label>
                <asp:TextBox ValidationGroup="SavePrice"  Width="100px" ID="txtCost" runat="server" onfocus="this.select();"></asp:TextBox>
                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" TargetControlID="txtCost" FilterType="Numbers,Custom" ValidChars=".-" runat="server">
                </cc1:FilteredTextBoxExtender>
                <asp:RequiredFieldValidator ValidationGroup="SavePrice" ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtCost" Display="Dynamic" CssClass="requiredField"
                                    ErrorMessage="required" Text="required"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td style="text-align:right; vertical-align:top;">
                <asp:Label CssClass="labelMessage" ID="label12" runat="server" Text="Dealer Price:"></asp:Label>
            </td>
            <td style="text-align:left; vertical-align:top;">
                <asp:Label CssClass="labelMessage"  ID="lblDealerPrice" runat="server"></asp:Label>
                <asp:TextBox ValidationGroup="SavePrice"  Width="100px" ID="txtDealerPrice" runat="server" onfocus="this.select();"></asp:TextBox>
                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="txtDealerPrice" FilterType="Numbers,Custom" ValidChars=".-" runat="server">
                </cc1:FilteredTextBoxExtender>
                <asp:RequiredFieldValidator ValidationGroup="SavePrice" ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtDealerPrice" Display="Dynamic" CssClass="requiredField"
                                    ErrorMessage="required" Text="required"></asp:RequiredFieldValidator>
                &nbsp;&nbsp;
                <asp:LinkButton ID="btnEdit" runat="server" OnClick="btnEdit_OnClick" >
                    <asp:Image runat="server" ImageUrl="~/Images/Edit.gif" ToolTip="Edit Price" />
                </asp:LinkButton>
                <asp:LinkButton ValidationGroup="SavePrice"  ID="btnSave" runat="server" OnClick="btnSave_OnClick" >
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/save.gif" ToolTip="Save" />
                </asp:LinkButton>
                <asp:LinkButton ID="btnCancel" runat="server" OnClick="btnCancel_OnClick" >
                    <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/Cancel.gif" ToolTip="Cancel" />
                </asp:LinkButton>
            </td>
        </tr>
        </div>
        <tr>
            <td style="text-align:right; vertical-align:top;">
                
            </td>
            <td style="text-align:left; vertical-align:top;">
                <asp:Button ID="btnAdd" runat="server" Text="Add to Purchase" OnClick="btnAdd_OnClick"></asp:Button>
                <asp:Button OnClientClick="return onAddProduct();" ID="btnNew" runat="server" Text="New Product" OnClick="btnNew_OnClick"></asp:Button>
                <asp:HiddenField ID="hidSessionID" runat="server" />
            </td>
        </tr>
    </table>
</asp:Panel>